import Vue from 'vue'
import AdminApp from './AdminApp.vue'
import PersonnerApp from './PersonnerApp'
import router from './router'
import store from './store'
import  Login from "./Login"
import axios from "axios";
import  filters from "@/filters"
import components from "@/components"
//引入ui 主库文件
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css/'
Vue.use(ElementUI);
Vue.use(filters);
Vue.use(components)
Vue.config.productionTip = false;
//请求拦截
axios.interceptors.request.use(function (config) {
    store.commit("CHANGE_ISLOADING",true);

    config.url = "/ele"+config.url+(config.url.includes("?")?"&":"?")+"t="+Date.now();
    config.headers={
        authorization:store.state.admin.token
    }
    // console.log(config)
    return config;
})
//响应拦截
axios.interceptors.response.use(function({data}){
  store.commit("CHANGE_ISLOADING",false);
  if(data.ok ===2){
    store.commit("OUT_LOGIN");
  }else{
    if(data.pageIndex)
      store.commit("CHANGE_PAGE_INFO",data)
      return data;
  }
  return data;
});


new Vue({
  router,
  store,
  mounted(){
    // store.state.admin.status
    // this.$store.state.admin.token?this.$store.state.admin.status?AdminApp:PersonnerApp:Login
  },
  render: function (h) { return h(
    this.$store.state.admin.token?this.$store.state.admin.status?AdminApp:PersonnerApp:Login
    ) }
}).$mount('#app')
